package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"strings"
)

const command = "cleanname"

var dir = flag.String("d", "", "prefix for unrooted names")

func usage() {
	fmt.Fprint(os.Stderr, "usage: ", command, " [ -d dir ] names ...\n")
	os.Exit(2)
}

func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() == 0 {
		usage()
	}
	for _, arg := range flag.Args() {
		if *dir != "" && !strings.HasPrefix(arg, "/") {
			arg = *dir + "/" + arg
		}
		fmt.Println(filepath.Clean(arg))
	}
	os.Exit(0)
}
